//
//  PrivacyPolicyView.swift
//  CMB250716
//
//  Created by Trae AI on 2025/01/16.
//

import SwiftUI

struct PrivacyPolicyView: View {
    @EnvironmentObject var dataManager: DataManager
    @Environment(\.dismiss) private var dismiss
    
    var body: some View {
        NavigationView {
            ZStack {
                Color(red: 0.08, green: 0.08, blue: 0.08)
                    .ignoresSafeArea()
                
                ScrollView {
                    VStack(alignment: .leading, spacing: 20) {
                        VStack(alignment: .leading, spacing: 15) {
                            Text(dataManager.currentLanguage == "zh" ? "Cu Mr Bull 隐私政策" : "Cu Mr Bull Privacy Policy")
                                .font(.title2)
                                .fontWeight(.bold)
                                .foregroundColor(.white)
                            
                            Text(dataManager.currentLanguage == "zh" ? "最后更新：2024年7月" : "Last Updated: July 2024")
                                .font(.caption)
                                .foregroundColor(.gray)
                        }
                        
                        VStack(alignment: .leading, spacing: 15) {
                            Text(dataManager.currentLanguage == "zh" ? "1. 信息收集" : "1. Information Collection")
                                .font(.headline)
                                .foregroundColor(.white)
                            ForEach(dataManager.currentLanguage == "zh" ? ["个人身份信息（姓名、电话、邮箱）", "订单与支付信息", "设备信息与使用数据", "位置信息（用于配送服务）"] : ["Personal identification information (name, phone, email)", "Order and payment information", "Device information and usage data", "Location information (for delivery services)"], id: \.self) { item in
                                Text("• " + item)
                                    .font(.system(size: 12))
                                    .foregroundColor(.white)
                            }
                            
                            Text(dataManager.currentLanguage == "zh" ? "2. 信息使用" : "2. Information Usage")
                                .font(.headline)
                                .foregroundColor(.white)
                            ForEach(dataManager.currentLanguage == "zh" ? ["处理订单与提供服务", "客户支持与沟通", "改善用户体验", "发送营销信息（需用户同意）"] : ["Process orders and provide services", "Customer support and communication", "Improve user experience", "Send marketing communications (with user consent)"], id: \.self) { item in
                                Text("• " + item)
                                    .font(.system(size: 12))
                                    .foregroundColor(.white)
                            }
                            
                            Text(dataManager.currentLanguage == "zh" ? "3. 信息共享" : "3. Information Sharing")
                                .font(.headline)
                                .foregroundColor(.white)
                            ForEach(dataManager.currentLanguage == "zh" ? ["支付平台（如 Stripe、Apple Pay、PayNow、Google Pay）", "营销通讯平台（如 WhatsApp Business、SMS、电子邮件）", "数据托管与分析服务（如 Firebase、Google Analytics）"] : ["Payment platforms (e.g., Stripe, Apple Pay, PayNow, Google Pay)", "Marketing communication platforms (e.g., WhatsApp Business, SMS, email)", "Hosting and analytics services (e.g., Firebase, Google Analytics)"], id: \.self) { item in
                                Text("• " + item)
                                    .font(.system(size: 12))
                                    .foregroundColor(.white)
                            }
                            Text(dataManager.currentLanguage == "zh" ? "我们承诺仅在业务必要范围内共享信息，并确保合作方遵守数据保护责任。" : "We ensure that shared data is limited to business needs and that all third parties are contractually obligated to protect your data.")
                                .font(.system(size: 12))
                                .foregroundColor(.white)
                            
                            Text(dataManager.currentLanguage == "zh" ? "4. 您的权利" : "4. Your Rights")
                                .font(.headline)
                                .foregroundColor(.white)
                            ForEach(dataManager.currentLanguage == "zh" ? ["查询或请求访问我们持有的您的个人资料", "请求更正错误信息", "请求撤销同意接收营销信息（点击退订链接或联系客服）"] : ["Request access to your personal data we hold", "Request correction of inaccurate information", "Withdraw consent for marketing communications (via unsubscribe link or by contacting us)"], id: \.self) { item in
                                Text("• " + item)
                                    .font(.system(size: 12))
                                    .foregroundColor(.white)
                            }
                            
                            Text(dataManager.currentLanguage == "zh" ? "5. 数据保护措施" : "5. Data Protection Measures")
                                .font(.headline)
                                .foregroundColor(.white)
                            ForEach(dataManager.currentLanguage == "zh" ? ["加密传输与存储", "访问权限限制与内部培训", "防火墙与安全备份机制"] : ["Secure transmission and encrypted storage", "Access control and staff training", "Firewalls and backup systems"], id: \.self) { item in
                                Text("• " + item)
                                    .font(.system(size: 12))
                                    .foregroundColor(.white)
                            }
                            
                            Text(dataManager.currentLanguage == "zh" ? "6. 数据保留期限" : "6. Data Retention")
                                .font(.headline)
                                .foregroundColor(.white)
                            ForEach(dataManager.currentLanguage == "zh" ? ["法律或税务规定的时限届满，或", "您注销账户后最长12个月"] : ["The legal or tax-related retention period ends, or", "Up to 12 months after you deactivate your account"], id: \.self) { item in
                                Text("• " + item)
                                    .font(.system(size: 12))
                                    .foregroundColor(.white)
                            }
                            
                            Text(dataManager.currentLanguage == "zh" ? "7. 隐私政策更新" : "7. Updates to Privacy Policy")
                                .font(.headline)
                                .foregroundColor(.white)
                            Text(dataManager.currentLanguage == "zh" ? "我们保留不经事先通知随时修改本政策的权利。修改后将更新版本日期，并通过 App 通知用户。\n\n如对隐私政策有任何疑问，请联系 info@cumrbull.com.sg。" : "We reserve the right to update this policy without prior notice. Any changes will be reflected with a new \"Last Updated\" date and notified through the App.\n\nFor any questions, please contact us at: info@cumrbull.com.sg")
                                .font(.system(size: 12))
                                .foregroundColor(.white)
                        }
                        .padding(20)
                    }
                }
            }
            .navigationTitle(dataManager.currentLanguage == "zh" ? "隐私政策" : "Privacy Policy")
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button(dataManager.currentLanguage == "zh" ? "完成" : "Done") {
                        dismiss()
                    }
                    .foregroundColor(Color(red: 1.0, green: 0.6, blue: 0.2))
                }
            }
        }
    }
}

#Preview {
    PrivacyPolicyView()
        .environmentObject(DataManager.shared)
}